
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 03/29/2015 12:17:59
-- Generated from EDMX file: F:\Documents\Study\Магистратура\НИР Ксюша\TransportAnalizer 2.0\Code\TransportAnalizer 2.0\Model\TransportAnalizerModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [TransportAnalizerDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_NodeTypeNode]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[NodeSet] DROP CONSTRAINT [FK_NodeTypeNode];
GO
IF OBJECT_ID(N'[dbo].[FK_NodeEdgeFrom]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EdgeSet] DROP CONSTRAINT [FK_NodeEdgeFrom];
GO
IF OBJECT_ID(N'[dbo].[FK_NodeEdgeTo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EdgeSet] DROP CONSTRAINT [FK_NodeEdgeTo];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[NodeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[NodeSet];
GO
IF OBJECT_ID(N'[dbo].[EdgeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EdgeSet];
GO
IF OBJECT_ID(N'[dbo].[NodeTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[NodeTypeSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'NodeSet'
CREATE TABLE [dbo].[NodeSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Location] geography  NOT NULL,
    [NodeTypeId] int  NOT NULL
);
GO

-- Creating table 'EdgeSet'
CREATE TABLE [dbo].[EdgeSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [NodeIdFrom] int  NOT NULL,
    [NodeIdTo] int  NOT NULL
);
GO

-- Creating table 'NodeTypeSet'
CREATE TABLE [dbo].[NodeTypeSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Regulation] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [Passage] float  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'NodeSet'
ALTER TABLE [dbo].[NodeSet]
ADD CONSTRAINT [PK_NodeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EdgeSet'
ALTER TABLE [dbo].[EdgeSet]
ADD CONSTRAINT [PK_EdgeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'NodeTypeSet'
ALTER TABLE [dbo].[NodeTypeSet]
ADD CONSTRAINT [PK_NodeTypeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [NodeTypeId] in table 'NodeSet'
ALTER TABLE [dbo].[NodeSet]
ADD CONSTRAINT [FK_NodeTypeNode]
    FOREIGN KEY ([NodeTypeId])
    REFERENCES [dbo].[NodeTypeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_NodeTypeNode'
CREATE INDEX [IX_FK_NodeTypeNode]
ON [dbo].[NodeSet]
    ([NodeTypeId]);
GO

-- Creating foreign key on [NodeIdFrom] in table 'EdgeSet'
ALTER TABLE [dbo].[EdgeSet]
ADD CONSTRAINT [FK_NodeEdgeFrom]
    FOREIGN KEY ([NodeIdFrom])
    REFERENCES [dbo].[NodeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_NodeEdgeFrom'
CREATE INDEX [IX_FK_NodeEdgeFrom]
ON [dbo].[EdgeSet]
    ([NodeIdFrom]);
GO

-- Creating foreign key on [NodeIdTo] in table 'EdgeSet'
ALTER TABLE [dbo].[EdgeSet]
ADD CONSTRAINT [FK_NodeEdgeTo]
    FOREIGN KEY ([NodeIdTo])
    REFERENCES [dbo].[NodeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_NodeEdgeTo'
CREATE INDEX [IX_FK_NodeEdgeTo]
ON [dbo].[EdgeSet]
    ([NodeIdTo]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------